Skip to content

ANDROID-16874 New comparator where order is not important#14

Merged
nimeacuerdo merged 2 commits intomainfrom
ANDROID-16874
Sep 23, 2025
Merged

ANDROID-16874 New comparator where order is not important#14
nimeacuerdo merged 2 commits intomainfrom
ANDROID-16874

Conversation

@nimeacuerdo
Copy link
Contributor

@nimeacuerdo nimeacuerdo commented Sep 23, 2025

🎟️ Jira ticket

ANDROID-16874

🥅 What's the goal?

Provide a new comparator where order does not matter

🚧 How do we do it?

Just provide a new public comparator

📘 Documentation changes?

  • No docs to update nor create

🧪 How can I test this?

  • Local testing in android-messenger with composite builds

@nimeacuerdo nimeacuerdo requested review from Copilot and dpastor and removed request for Copilot September 23, 2025 09:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new log comparator that compares lists without considering order, addressing Android ticket ANDROID-16874. The implementation provides an alternative to the existing DefaultLogComparator for scenarios where log entry sequence is not important.

  • Adds AnyOrderLogComparator class that compares log lists ignoring order
  • Implements difference detection to identify missing and extra entries
  • Provides detailed error messages showing which entries are missing or extra

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

private fun findDifference(first: List<LogType>, second: List<LogType>): List<LogType> {
return first.toMutableList().apply { removeAll(second) }
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation has O(n²) complexity due to removeAll() operation. For better performance with large lists, consider using a frequency-based approach or converting to sets if duplicates should be ignored.

Suggested change
return first.toMutableList().apply { removeAll(second) }
val freqMap = mutableMapOf<LogType, Int>()
for (item in first) {
freqMap[item] = freqMap.getOrDefault(item, 0) + 1
}
for (item in second) {
val count = freqMap[item]
if (count != null && count > 0) {
freqMap[item] = count - 1
}
}
val result = mutableListOf<LogType>()
for ((item, count) in freqMap) {
repeat(count) {
result.add(item)
}
}
return result

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new set-based approach pushed

} No newline at end of file
}

@Suppress("unused")
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @Suppress("unused") annotation suggests this class might not be used yet. Consider removing this suppression once the class is properly integrated and used in the codebase.

Suggested change
@Suppress("unused")

Copilot uses AI. Check for mistakes.
Copy link

@dpastor dpastor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't we apply it to any test yet?

@nimeacuerdo
Copy link
Contributor Author

nimeacuerdo commented Sep 23, 2025

won't we apply it to any test yet?

We will -> https://github.com/Telefonica/android-messenger/pull/3150

@nimeacuerdo nimeacuerdo merged commit d0c9cae into main Sep 23, 2025
3 checks passed
@nimeacuerdo nimeacuerdo deleted the ANDROID-16874 branch September 23, 2025 14:42
@nimeacuerdo nimeacuerdo added the enhancement New feature or request label Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants